hi,
i got
and want to convert it toCode:char word [80]
is it possible?Code:char *word
hi,
i got
and want to convert it toCode:char word [80]
is it possible?Code:char *word
Well *word is a pointer to a char, which can point to any address of a variable of type char. Which basicaly mean that scalar vallue of char * would be set to 1.
So you could do this
So you are making the word to point to word_str. So now then. What would you expect when I type thisCode:char word_str[20] = { "Hello World"}; word = word_str
???Code:printf("%s", word);
ssharish
> is it possible?
Depends, how were you using the array to begin with?
Generally, the answer is yes, providing that you arrange for the pointer to point to 80 chars of memory before attempting to use the space (ssharish2005 showed one way).
However, there are a few instances where a direct replacement is not possible without causing other changes in the program. An example would be using sizeof()
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.